package com.angel.provider.health.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.angel.core.base.BaseProviderImpl;
import com.angel.core.util.DateUtils;
import com.angel.dao.health.BuzDoctorMapper;
import com.angel.dao.health.BuzDoctorWorkLogMapper;
import com.angel.dao.health.BuzDoctorWorkMapper;
import com.angel.health.BuzDoctor;
import com.angel.health.BuzDoctorWork;
import com.angel.health.BuzDoctorWorkLog;
import com.angel.provider.health.BuzDoctorWorkProvider;

/** 
* @author 作者姓名  cheng
* @version 
* 创建时间：2016年11月16日 下午5:45:05 
* 类说明 
*/
@Service
public class BuzDoctorWorkProviderImpl extends BaseProviderImpl<BuzDoctorWork> implements BuzDoctorWorkProvider {

	@Autowired
	private BuzDoctorWorkMapper bdwMapper;
	@Autowired
	private BuzDoctorWorkLogMapper bdwlMapper;
	@Autowired
	private BuzDoctorMapper bdMapper;
	
	@Override
	public List<Map<String, Object>> findWorkAll(BuzDoctorWork bdw) {
		// TODO Auto-generated method stub
		List<Map<String, Object>> bdwList = bdwMapper.findAll(bdw);
		BuzDoctorWorkLog bdwl = new BuzDoctorWorkLog();
		for(int i = 0;i<bdwList.size();i++){
			String doctorId = bdwList.get(i).get("doctorId").toString();
			String workDate = bdwList.get(i).get("workDate").toString();
			bdwl.setDoctorId(Integer.parseInt(doctorId));
			bdwl.setWorkDate(workDate);
			List<BuzDoctorWorkLog> bdwlList = bdwlMapper.selectAll(bdwl);
			bdwList.get(i).put("logList", bdwlList);
		}
		return bdwList;
	}

	@Override
	public List<Map<String, Object>> findWorkDate(BuzDoctorWork bdw) {
		// TODO Auto-generated method stub
		String now = DateUtils.getNowForStr();
		bdw.setBeginDate(now);
		bdw.setEndDate(DateUtils.plusDay(6,now));
		List<Map<String, Object>> bdwList = bdwMapper.findAll(bdw);
		Map<String,Object> map = new HashMap<String,Object>();
		BuzDoctor bd = bdMapper.selectByPrimaryKey(bdw.getDoctorId());
		for(int i = 0;i<bdwList.size();i++){
			String doctorId = bdwList.get(i).get("doctorId").toString();
			String workDate = bdwList.get(i).get("workDate").toString();
			map.put(workDate, doctorId);
		}
		
		List<Map<String, Object>> workList = new ArrayList<Map<String, Object>>();
		
		for(int i=0;i<7;i++){
			String _now = DateUtils.plusDay(i,now);
			Map<String,Object> _map = new HashMap<String,Object>();
			_map.put("doctorId", bdw.getDoctorId());
			_map.put("workDate", _now);
			_map.put("mobile", bd.getMobile());
			if(map.get(_now) == null){
				_map.put("workType", 0);
			}else{
				_map.put("workType", 1);
			}
			workList.add(_map);
		}
		return workList;
	}

	@Override
	public int delete(BuzDoctorWork bdw) {
		// TODO Auto-generated method stub
		return bdwMapper.delete(bdw);
	}

}
